﻿using LayIM.AspNetCore.Core.Application;
using LayIM.AspNetCore.Core.Storage;
using LayIM.AspNetCore.Storage.Infra.Dapper;
using LayIM.AspNetCore.Storage.Infra.Dapper.Repository;


namespace Microsoft.Extensions.DependencyInjection
{

    public static class StorageSqlServerExtensions
    {
        /// <summary>
        /// 使用SqlServer
        /// </summary>
        /// <param name="services"></param>
        /// <param name="setConfig"></param>
        public static IServiceCollection AddSqlServer(this IServiceCollection services,string connectionString)
        {
            var dbConfig = new DBConnectionConfig(DBType.SqlServer)
            {
                ConnectionString = connectionString
            };

            services.AddSingleton(dbConfig);

            services.AddSingleton<ILayIMStorage, LayIMDapperStorage>();

            RegisterRepositories(services);

            return services;
        }

        private static void RegisterRepositories(IServiceCollection services)
        {
            services.AddSingleton<BigGroupRepository>();
            services.AddSingleton<FriendGroupRepository>();
            services.AddSingleton<FriendRelationRepository>();
            services.AddSingleton<GroupMemberRepository>();
            services.AddSingleton<UserRepository>();
            services.AddSingleton<ChatRecordRepository>();
        }

    }
}

